<template>
	<view class="container">
		<!-- <view class="qrcode">
			<uqrcode ref="qr6" canvas-id="qr6" :value="text" :size="size" :start="true" :auto="true" :queue="queue"
				:options="{
					foregroundImageSrc: logo,
					foregroundImageWidth: size / 5,
					foregroundImageHeight: size / 5,
					drawReserve: queue
				}" @click="remake('qr6')" @complete="complete($event, 'qr6')"></uqrcode>
		</view> -->
		<view class="btns">
			<!-- <button class="btn" type="primary" @click="save('qr6')">保存图片到手机</button> -->
			<button class="btn" type="primary" @click="share">分享链接给好友</button>
		</view>
	</view>
</template>

<script>

export default {
	props: {
		text: {
			type: String,
			required: true,
		},
		logo: {
			type: String,
			default: '', // logo URL
		},
		type: {
			type: String,
			default: '',
		},
		param: {
			type: Object,
			default: {}, // logo URL
		},
	},
	data() {
		return {
			size: 200,
			// #ifndef APP-NVUE
			queue: false,
			// #endif
			// #ifdef APP-NVUE
			queue: true
			// #endif
		};
	},
	created() {
		console.log(this.text,'11111',this.param);
	},
	methods: {
		share() {
			uni.share({
				provider: "weixin",
				scene: "WXSceneSession",
				imageUrl: "https://feishazoushi.cn/appImages/logo.png",
				title: "Hi~请帮我充值",
				...this.param,
				success: function (ret) {
					console.log("share success", JSON.stringify(ret));
				},
				fail: function (fail) {
					console.log(fail);
				},
			});
		},
		remake(refName) {
			var ref = this.$refs[refName];
			/* ref通过v-for遍历后会自动包裹在数组里，所以要判断一下 */
			if (Array.isArray(ref)) {
				ref[0].remake();
			} else {
				ref.remake();
			}
		},
		complete(e, refName) {
			if (e.success) {
				console.log(refName + '生成成功');
			} else {
				console.log(refName + '生成失败');
			}
		},
		save(refName) {
			uni.showLoading({
				title: '保存中',
				mask: true
			});
			var ref = this.$refs[refName];
			/* ref通过v-for遍历后会自动包裹在数组里，所以要判断一下 */
			if (Array.isArray(ref)) {
				ref[0].save({
					success: res => {
						uni.hideLoading();
						uni.showToast({
							icon: 'success',
							title: '保存成功'
						});
					},
					fail: err => {
						uni.showToast({
							icon: 'none',
							title: JSON.stringify(err)
						});
					}
				});
			} else {
				ref.save({
					success: res => {
						uni.hideLoading();
						uni.showToast({
							icon: 'success',
							title: '保存成功'
						});
					},
					fail: err => {
						uni.showToast({
							icon: 'none',
							title: JSON.stringify(err)
						});
					}
				});
			}
		},
	}
};
</script>

<style lang="scss" scoped>
.qrcode {
	display: flex;
	justify-content: center;
}

.container {
	padding-top: 200rpx;

	.btns {

		display: flex;
		justify-content: space-between;
		margin: 160rpx auto 0;

		.btn {
			width: 330rpx;
		}
	}
}
</style>